﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace aaaaa
{
    class Light
    {
        #region Fog

        /// <summary>
        /// Fog color. For fade
        /// </summary>
        private Color fogColor;
        public Color FogColor
        {
            get { return fogColor; }
            set { fogColor = value; }
        }
        /// <summary>
        /// Fog starts here
        /// </summary>
        private float fogStart = 10;
        public float FogStart
        {
            get { return fogStart; }
            set
            {
                fogStart = value;
            }
        }
        
        /// <summary>
        /// Fog ends here
        /// </summary>
        private float fogEnd = 20;
        public float FogEnd
        {
            get { return fogEnd; }
            set
            {
              fogEnd = value;
            }
        }

        #endregion

        public Color diffuseColor0;
        //se não for SETado, e não tiver configurado... vai ficar tudo preto \o
        public Color diffuseColor1;
        public Color diffuseColor2;

        public Vector3 diffuseDirection0;
        public Vector3 diffuseDirection1;
        public Vector3 diffuseDirection2;

        public bool enableDefaultLighting;
        public bool enableDirectionalLighting0;
        public bool enableDirectionalLighting1;
        public bool enableDirectionalLighting2;       

        public Color emissiveColor;

        /// <summary>
        ///  true to use per-pixel lighting if it is available; false to disable per-pixel lighting. The default value is true. When PreferPerPixelLighting is true, if the graphics adapter does not support a minimum of Pixel Shader Model 2.0, BasicEffect will automatically fall-back to per-vertex lighting. When PreferPerPixelLighting is false, per-vertex lighting is used regardless of whether per-pixel lighting is supported by the graphics adapter.
         ///  There are two common types of real-time lighting used in games. Per-vertex lighting is where lighting contributions are determined at each vertex and then the results are interpolated across the triangle. Depending on how tessellated the mesh is, this can result in severe artifacts. Per-pixel lighting interpolates the per-vertex normal across the triangle, but calculates the contribution at each pixel, which results in much smoother lighting, particularly when a specular highlight falls between vertices.
        /// </summary>
        public bool PreferPerPixelLighting;

        public Type currentType = Type.None;

        public enum Type
        {
            None,
            Ambient,
            OneDirection,
            TwoDirections,
            ThreeDirections,
            DefautIlumination,
            Specular,
            Emissive,
            Texturizated,
            Fog,
        }

        public Light(Type lightType)
        {
            currentType = lightType;

        }
        /// <summary>
        /// Constructor for one light
        /// </summary>
        /// <param name="lightType">the type of the light</param>
        /// <param name="diffuseColor0">The color</param>
        /// <param name="diffuseDirection0">The direction</param>
        public Light(Type lightType, Color diffuseColor0, Vector3 diffuseDirection0)
        {
            enableDefaultLighting = true;
            enableDirectionalLighting0 = true;
            this.diffuseColor0 = diffuseColor0;
            this.diffuseDirection0 = diffuseDirection0;
        }

        /// <summary>
        /// Constructor for light fog
        /// </summary>
        /// <param name="lightType">The type of the light</param>
        /// <param name="fogStart">Fog starts here</param>
        /// <param name="fogEnd">Fog ends here</param>
        /// <param name="fogColor">The color for fade</param>
        public Light(Type lightType, float fogStart, float fogEnd, Color fogColor)
        {
            currentType = lightType;
            this.FogColor = fogColor;
            this.FogStart = fogStart;
            this.FogEnd = fogEnd;

        }


        public Light(Type lightType, Color emissiveColor)
        {
            currentType = lightType;
            this.emissiveColor = emissiveColor;
            //this.diffuseDirection0 = diffuseDirection;
            //enableDirectionalLighting0 = true;
            ////basicEffect.LightingEnabled = true;
            //                basicEffect.DirectionalLight0.Enabled = true;
            //                //basicEffect.EmissiveColor = emissiveColor.ToVector3();
            //                basicEffect.DirectionalLight0.DiffuseColor = emissiveColor.ToVector3();
            //                basicEffect.DirectionalLight0.Direction = Vector3.Normalize(diffuseDirection0);

        }

        //private void changeLightType()
        //{
        //    switch (currentType)
        //    {
        //        case Type.None:
        //            //não tem configuração      

        //            break;

        //        case Type.DefautIlumination:
        //            basicEffect.EnableDefaultLighting();
        //            break;

        //        case Type.OneDirection:
        //            diffuseColor0 = new Color(255, 0, 0);
        //            diffuseDirection0 = new Vector3(1, 0, 0);
        //            basicEffect.EnableDefaultLighting();
        //            basicEffect.DirectionalLight0.Enabled = true;
        //            basicEffect.DirectionalLight0.DiffuseColor = diffuseColor0.ToVector3();
        //            basicEffect.DirectionalLight0.Direction = Vector3.Normalize(diffuseDirection0);

        //            break;

        //        case Type.TwoDirections:

        //            diffuseColor0 = new Color(255, 0, 0);
        //            diffuseColor1 = new Color(0, 255, 0);
        //            diffuseDirection0 = new Vector3(1, 0, 0);
        //            diffuseDirection1 = new Vector3(-1, 0, 0);

        //            basicEffect.EnableDefaultLighting();
        //            basicEffect.DirectionalLight0.Enabled = true;
        //            basicEffect.DirectionalLight0.DiffuseColor = diffuseColor0.ToVector3();
        //            basicEffect.DirectionalLight0.Direction = Vector3.Normalize(diffuseDirection0);

        //            basicEffect.DirectionalLight1.Enabled = true;
        //            basicEffect.DirectionalLight1.DiffuseColor = diffuseColor1.ToVector3();
        //            basicEffect.DirectionalLight1.Direction = Vector3.Normalize(diffuseDirection1);

        //            break;

        //        case Type.ThreeDirections:

        //            diffuseColor0 = new Color(255, 0, 0);
        //            diffuseColor1 = new Color(0, 255, 0);
        //            diffuseColor2 = new Color(0, 255, 255);
        //            diffuseDirection0 = new Vector3(1, 0, 0);
        //            diffuseDirection1 = new Vector3(-1, 0, 0);
        //            diffuseDirection2 = new Vector3(0, 1, 0);

        //            basicEffect.EnableDefaultLighting();
        //            basicEffect.DirectionalLight0.Enabled = true;
        //            basicEffect.DirectionalLight0.DiffuseColor = diffuseColor0.ToVector3();
        //            basicEffect.DirectionalLight0.Direction = Vector3.Normalize(diffuseDirection0);

        //            basicEffect.DirectionalLight1.Enabled = true;
        //            basicEffect.DirectionalLight1.DiffuseColor = diffuseColor1.ToVector3();
        //            basicEffect.DirectionalLight1.Direction = Vector3.Normalize(diffuseDirection1);

        //            basicEffect.DirectionalLight2.Enabled = true;
        //            basicEffect.DirectionalLight2.DiffuseColor = diffuseColor2.ToVector3();
        //            basicEffect.DirectionalLight2.Direction = Vector3.Normalize(diffuseDirection2);
                    
                    //enableDefaultLighting = true;

                    //enableDirectionalLighting0 = true;
                    //enableDirectionalLighting1 = true;
                    //enableDirectionalLighting2 = true;
        //            break;

                    //PreferPerPixelLighting = true;
                                        
                    //basicEffect.DirectionalLight0.Enabled = true;
                    //basicEffect.DirectionalLight0.DiffuseColor = diffuseColor0.ToVector3();
                    //basicEffect.DirectionalLight0.Direction = Vector3.Normalize(diffuseDirection0);
        //        case Type.Fog:
                    

        //            break;

        //        //TODO: Implementar o draw respectivo para cada case no construtor
        //        //victor Cruz: fog
        //        // rafael: Specular
        //        // leandro moreira: DefautIlumination
        //        // Lucas Muzitano: ThreeDirections
        //        //Thiago Lessa: Emissive
        //        // Rego Silva: None, Ambient, OneDirection, TwoDirections
        //    
        //

                   // basicEffect.DirectionalLight2.Enabled = true;
    //                basicEffect.DirectionalLight2.DiffuseColor = diffuseColor2.ToVector3();
    //                basicEffect.DirectionalLight2.Direction = Vector3.Normalize(diffuseDirection2);

    //                break;

    //            case Type.Emissive:
    //                basicEffect.LightingEnabled = true;
    //                basicEffect.DirectionalLight0.Enabled = true;
    //                //basicEffect.EmissiveColor = emissiveColor.ToVector3();
    //                basicEffect.DirectionalLight0.DiffuseColor = emissiveColor.ToVector3();
    //                basicEffect.DirectionalLight0.Direction = Vector3.Normalize(diffuseDirection0);

    //                break;
                    
    //                //TODO: Implementar o draw respectivo para cada case no construtor
    //                //victor Cruz: fog
    //                // rafael: Specular
    //               // leandro moreira: DefautIlumination
    //                // Lucas Muzitano: ThreeDirections
    //                //Thiago Lessa: Emissive
    //                // Rego Silva: None, Ambient, OneDirection, TwoDirections
    //        }
    //    }
    }
}